#include "get_song_info.h"
#include "json_parser.h"
#include <stdlib.h>
#include <string.h>

int main(int c, char **v)
{
    if (c != 2)
    {
        printf("Usage: %s [songid or sharelink]\n", v[0]);
        return -1;
    }
    long long int cod = atoll(v[1]);
    if (cod == 0)
    {
        if (strlen(v[1]) > 34)
        {
            cod = atoll(v[1] + 33);
        }
    }
    if (cod == 0)
    {
        printf("Error Parsing SongID\n"
               "Usage:\t%s [songid]\n"
               "\t\t%s [song-url]",
               v[0], v[0]);
        return -1;
    }
    init_curl();
    getnet_set_songid(cod);
    //getnet_get_songinfo_file();
    char *data_json = getnet_get_songinfo();
    song_info_t *info = parse_songinfo_json(data_json);
    if (!info)
    {
        puts("Got nothing...\n");
        return -1;
    }
    printf("name:\t\t%s\n", info->name);
    printf("alias:\t\t%s\n", info->alias);
    printf("translation:\t%s\n", info->transname);
    printf("artist:\t\t%s\n", info->artist);
    printf("album:\t\t%s\n", info->album);
    printf("disc:\t\t%s\n", info->disc);
    printf("index:\t\t%d\n", info->index);
    printf("cover url:\t%s\n", info->album_picurl);
    puts("");
    getnet_get_cover_file(info->album_picurl);
    end_curl();
    return 0;
}